import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
// 导入字体图标
import './assets/css/global.css'
// 导入全局样式
import './assets/fonts/iconfont.css'

// 导入带树形结构得表格
import TreeTable from 'vue-table-with-tree-grid'

// 导入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'

import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme

Vue.use(VueQuillEditor /* { default global options } */)
Vue.component('tree-table', TreeTable)

// 导入进度条
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// 导入axios
import axios from 'axios'
// 设置默认根路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
// 请求拦截器，每次发送请求时携带token
axios.interceptors.request.use(function(config) {
  config.headers.Authorization = window.sessionStorage.getItem('token')
  NProgress.start()
  // console.log(config)
  return config
})
// 响应拦截器，每次发送请求时携带token
axios.interceptors.response.use(function(config) {
  config.headers.Authorization = window.sessionStorage.getItem('token')
  NProgress.done()
  // console.log(config)
  return config
})
// 将axios挂载到Vue的原型中
Vue.prototype.$http = axios

//注册一个全局时间过滤器
Vue.filter('dateFormat', function(dateStr, pattern = '') {
  // 根据给定的时间字符串， 得到特定的时间
  var dt = new Date(dateStr)

  // yyyy-mm-dd
  var y = dt.getFullYear()
  var m = (dt.getMonth() + 1).toString().padStart(2, '0')
  var d = dt
    .getDate()
    .toString()
    .padStart(2, '0')
  if (pattern.toLowerCase() === 'yyyy-mm-dd') {
    return `${y}-${m}-${d}`
  } else {
    var hh = dt
      .getHours()
      .toString()
      .padStart(2, '0')
    var mm = dt
      .getMinutes()
      .toString()
      .padStart(2, '0')
    var ss = dt
      .getSeconds()
      .toString()
      .padStart(2, '0')
    return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
  }
})
Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
